package org.example.everyday;

public class Lc2104 {
    public static void main(String[] args) {
        Lc2104 lc2104 = new Lc2104();
        int[] array = {1,2,3};
        long result =  lc2104.subArrayRanges(array);
        System.out.println(result);
    }

    public long subArrayRanges(int[] nums) {
        int n = nums.length;
        long ret = 0;
        for (int i = 0; i < n; i++) {
            int minVal = Integer.MAX_VALUE,maxVal = Integer.MIN_VALUE;
            for (int j = i; j < n; j++) {
                minVal = Math.min(minVal,nums[j]);
                maxVal = Math.max(maxVal,nums[j]);
                ret += maxVal - minVal;
            }
        }

        return ret;
    }
}
